/*
	The Print button on the thread list.
	Repeats the current search, extracts the result threads, and loads into a new window. 
*/


function PrintButtonUI(gtdinboxPage){
	this._gtdinboxPage = gtdinboxPage;
	this._doc = this._gtdinboxPage.doc;
	this._eventObservers = new EventObservers(this);
};

PrintButtonUI.prototype.viewChange = function(){

try{
	// Test to see if the view is set to search
	if( !/(\/#search|\/#label)/.test(this._doc.location.href) ){	// Not a search page
		if( this.elButton ) this.elButton.style.display = "none";
		return;
	}else{
		if( this.elButton ) this.elButton.style.display = "";
	}
	
	if( !this.elButton ){	// Add it to the UI
		this.elButton = this._doc.createElement("BUTTON");
			this.elButton.className = "BuNwUe";
			this.elButton.innerHTML = this._gtdinboxPage.stringBundle.getString("Print.Button");
		var elContainer = this._gtdinboxPage.gmailDOM.element("delete-button");
			elContainer = elContainer.parentNode;
		elContainer.appendChild( this.elButton );
		
		this._eventObservers.observe( this.elButton, "click", this.clickPrint, false );
	}
}catch(e){
	if( GTDDEBUGMODE ) alert("PrintButton viewChange\n" + e.toString());
}	
};

PrintButtonUI.prototype.clickPrint = function(){
	// Repeat the current search in a data format; creating a set of threads. Then load a new window.
try{
	var searcher = new Searcher(this._gtdinboxPage);
	searcher.searchCurrentQuery();
	
}catch(e){
	if( GTDDEBUGMODE ) alert("PrintButton clickPrint\n" + e.toString());
}	
};


PrintButtonUI.prototype.destroy = function(){
	this._eventObservers.destroy();
};